package com.lxw.station.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class HelloController {
    @Resource
    RedisTemplate<String,Object> redisTemplate;
    @RequestMapping("/hello")
    public Object hello(HttpServletRequest request) {


        String remoteUser = request.getRemoteUser();
        log.info("remoteUser = " + remoteUser);
        String localAddr = request.getLocalAddr();
        log.info("localAddr = " + localAddr);
        // remoteAddr = 222.222.120.75
        String remoteAddr = request.getRemoteAddr();
        log.info("remoteAddr = " + remoteAddr);
        // remoteHost = 222.222.120.75
        String remoteHost = request.getRemoteHost();
        log.info("remoteHost = " + remoteHost);
        // ipAddress = 222.222.120.88
        String ipAddress = request.getHeader("X-Forwarded-For");
        log.info("ipAddress = " + ipAddress);
        return "ok";
    }
    @RequestMapping("/helloRedis")
    public Object helloRedis(){
        ValueOperations<String, Object> operations = redisTemplate.opsForValue();
        operations.set("name","张三三");
        return operations.get("name");

    }
}
